package gr.handmademarket.bl.operations;

import gr.handmademarket.hibernate.HibernateUtil;
import gr.handmademarket.po.implementations.NewsLetterReceipient;

import org.hibernate.Session;

/**
 * NewsLetterOperation.
 */
public class NewsLetterOperation {

	/**
	 * the user.
	 */
	private NewsLetterReceipient receipient;
	
	
	/**
	 * NewsLetterOperation. 
	 *
	 */
	public NewsLetterOperation() {
		// empty
	}
	
	/**
	 * execution method.
	 */
	@SuppressWarnings("nls")
	public void execute(){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        if (session.get(NewsLetterReceipient.class, receipient.getEmail()) != null){
        	throw new RuntimeException("email already registered !");
        }else{
        	session.save(receipient);
        }
        session.getTransaction().commit();
	}

	/**
	 * @param receipient
	 */
	public void setReceipient(NewsLetterReceipient receipient) {
		this.receipient = receipient;
	}
	
}
